<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="举报人" prop="name">
        <el-input placeholder="请输入昵称" v-model="queryParams.name" />
      </el-form-item>
      <el-form-item label="举报类型" prop="report">
        <el-select v-model="queryParams.report" clearable>
          <el-option v-for="(item,index) in arr" :key="index" :label="item.content" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="处理状态" prop="status">
        <el-select v-model="queryParams.status" clearable>
          <el-option label="未处理" :value="0" />
          <el-option label="无需处理" :value="1" />
          <el-option label="已下架" :value="2" />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="选择时间" prop="startTime">
        <el-date-picker
      v-model="queryParams.startTime"
      type="date"
      placeholder="开始日期">
    </el-date-picker>
</el-form-item>——
<el-form-item prop="endTime">
<el-date-picker
      v-model="queryParams.endTime"
      type="date"
      placeholder="结束日期">
    </el-date-picker>
</el-form-item>
        <el-form-item> -->
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <!-- <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >新增</el-button>
        </el-col> -->
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
          >处理状态</el-button>
        </el-col>
        <!-- <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >处理下架</el-button>
        </el-col> -->
        <!-- <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:sysReport:export']"
          >导出</el-button>
        </el-col> -->
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="sysReportList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" align="center" prop="id" />
        <el-table-column label="举报时间" align="center" prop="createTime" />
        <el-table-column label="举报类型" align="center" prop="report" />
        <el-table-column label="被举报内容" align="center">
            <template slot-scope="scope">
    <el-button type="primary" @click="openModal(scope.row)">查看</el-button>
  </template>
      </el-table-column>
        </el-table-column>
        <el-table-column label="处理状态" align="center" prop="status">
            <template slot-scope="scope">
                <span>
                    {{ scope.row.status == 0?"未处理":scope.row.status == 1?"无需处理":scope.row.status == 2?"已下架":null }}
                </span>
            </template>
        </el-table-column>
        <el-table-column label="举报人" align="center" prop="name" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >处理状态</el-button>
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >处理下架</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 查看原文 -->
      <el-dialog :visible.sync="videoModal" width="50%" 
    :before-close="handleClose" title="详情">
    <div class="videoInfo" >
    <span v-if="type == 1" v-html="textContent"></span>
    <span v-if="type == 2" v-html="textContent"></span>
    <div class="videoInfo">
    <video v-if="type == 3" :src="textContent" controls autoplay></video>
    </div>
    <span v-if="type == 4" v-html="textContent"></span>
    <img v-if="type == 5" :src="textContent" :width="200" :height="200" />
    <span v-if="type == 6" v-html="textContent"></span>
    </div>

</el-dialog>
  
      <!-- 添加或修改举报类型对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="处理状态" prop="status">
        <el-select v-model="form.status" clearable>
          <el-option label="未处理" :value="0" />
          <el-option label="无需处理" :value="1" />
          <el-option label="已下架" :value="2" />
        </el-select>
      </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { getSysReport,upSysReport } from "@/api/system/reportRecords";
  import { listSysReport } from "@/api/system/sysReport";
  
  export default {
    name: "SysReport",
    data() {
      return {
        // value1:null,
        //举报类型
        arr:null,
        type:null,
        //原文数据
        textContent:null,
        videoModal: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 举报类型表格数据
        sysReportList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        queryParam:{
            pageNum: 1,
          pageSize: 30,
          // content: null,
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name:null,
          report:null,
          status:null,
          startTime:null,
          endTime:null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
        openModal(str) {
            if(str.type == 1){
                if(str.text.contentType == 0){
                this.type = str.type
                this.textContent = str.text.contentTitle
                }else if(str.text.contentType == 1){
                    this.type = 3;
                    if(!str.text.vedioUrl.startsWith('http')){
                      this.textContent = process.env.VUE_APP_BASE_API+str.text.vedioUrl
                    }else{
                      this.textContent = str.text.vedioUrl
                    }
                    
                }else if(str.text.contentType == 2){
                    this.type = 3;
                    if(!str.text.vedioUrl.startsWith('http')){
                      this.textContent = process.env.VUE_APP_BASE_API+str.text.vedioUrl
                    }else{
                      this.textContent = str.text.vedioUrl
                    }
                    // this.textContent = str.text.vedioUrl
                }
                // else if(str.text.contentType == 4){
                // }
                
            }
            if(str.type == 2){
                this.type = str.type
                this.textContent = str.text.text
            }
            if(str.type == 3){
                this.type = 3
                if(!str.text.musicWav){
                  if(!str.text.vedioUrl.startsWith('http')){
                      this.textContent = process.env.VUE_APP_BASE_API+str.text.vedioUrl
                    }else{
                      this.textContent = str.text.vedioUrl
                    }
                    // this.textContent = str.text.videoUrl
                }else{
                  if(!str.text.musicWav.startsWith('http')){
                      this.textContent = process.env.VUE_APP_BASE_API+str.text.musicWav
                    }else{
                      this.textContent = str.text.musicWav
                    }
                    // this.textContent = str.text.musicWav
                }
                
            }
            if(str.type == 4){
                this.type = str.type
                this.textContent = str.text.text
            }
            if(str.type == 5){
                this.type = 3
                if(!str.text.contentUrl.startsWith('http')){
                      this.textContent = process.env.VUE_APP_BASE_API+str.text.contentUrl
                    }else{
                      this.textContent = str.text.contentUrl
                    }
                // this.textContent = str.text.contentUrl
            }
            if(str.type == 6){
                this.type = str.type
                this.textContent = str.text.text
            }
    this.videoModal = true;
  },
  handleClose() {
    this.videoModal = false;
    // this.videoSrc = '';
  },
      /** 查询举报类型列表 */
      getList() {
        this.loading = true;
        getSysReport(this.queryParams).then(response => {
          this.sysReportList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
        listSysReport(this.queryParam).then(response => {
        this.arr = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          status: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;

        // this.queryParams.startTime = (this.queryParams.startTime).getTime()
        // this.queryParams.endTime = (this.queryParams.endTime).getTime()
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加举报类型";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        // const id = row.id || this.ids
        // getSysReport(id).then(response => {
        //   this.form = response.data;
        this.form.id = row.id
        this.form.status = row.status
          console.log('====================================');
          console.log(this.form.status);
          console.log('====================================');
          this.open = true;
          this.title = "修改处理状态";
        // });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
                upSysReport(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addSysReport(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除举报类型编号为"' + ids + '"的数据项？').then(function() {
          return delSysReport(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('system/sysReport/export', {
          ...this.queryParams
        }, `sysReport_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
<style>
.videoInfo{
  display: flex; justify-content: center; align-items: center; height: 100%;
}
video{
  width:100%;
  height: 100%;
}
</style>